package com.unipv14.androidgallery;

import fileManagers.FilterImage;
import imageViewer.ImageListener;

import java.util.LinkedList;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

public class CurrentImageActivity extends Activity {
	
	private ImageListener listener;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		hideTitle();
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_current_image);
		ImageView picView = (ImageView) findViewById(R.id.current_image);
		ImageView otherImage=(ImageView)findViewById(R.id.nextImage);
		DisplayMetrics screenSize=new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(screenSize);
		String[] paths=getIntent().getExtras().getStringArray("list");
		LinkedList<String> pathsList=new LinkedList<String>();
		FilterImage filterImage = new FilterImage();
		for(int i=0;i<paths.length;i++){
			String currentPath=paths[i];
			if(filterImage.checkFilter(currentPath, "")){
				pathsList.add(currentPath);
			}
		}	
		paths=pathsList.toArray(paths);
		String selectedFile=getIntent().getExtras().getString("current_image");
		int position=pathsList.indexOf(selectedFile);
		listener=new ImageListener(paths,position, picView,
				otherImage, screenSize.widthPixels,this,screenSize.heightPixels);
		
}

	public void hideTitle() {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		listener.manageTouch(event);
		return super.onTouchEvent(event);
	}

}
